package com.moyun.search.controller;

import com.moyun.search.common.base.BaseController;
import com.moyun.search.common.result.Result;
import com.moyun.search.common.result.ResultUtil;
import com.moyun.search.service.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传接口
 * @author: zealon
 * @since: 2021/12/22
 */
@RestController
@RequestMapping("file")
public class FileController extends BaseController {

    @Autowired
    private FileUploadService fileUploadService;

    @PostMapping("upload")
    public Result upload(@RequestParam("file") MultipartFile[] files, @RequestParam("projectId") Integer projectId){
        if (files.length == 0) {
            return ResultUtil.verificationFailed().buildMessage("file字段请传入文件!");
        }
        return this.fileUploadService.upload(files[0], projectId);
    }
}
